package stage_1_module_3.code.homework_5;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Set;

public class Opt {
    
    public static List<Card> init() {
        List<Card> hs = new ArrayList<>();
        addCard(hs, "大王", 1);
        addCard(hs, "小王", 1);
        addCard(hs, "2", 4);
        addCard(hs, "A", 4);
        addCard(hs, "K", 4);
        addCard(hs, "Q", 4);
        addCard(hs, "J", 4);
        addCard(hs, "10", 4);
        addCard(hs, "9", 4);
        addCard(hs, "8", 4);
        addCard(hs, "7", 4);
        addCard(hs, "6", 4);
        addCard(hs, "5", 4);
        addCard(hs, "4", 4);
        addCard(hs, "3", 4);
        return hs;
    }

    private static void addCard(List<Card> lc, String code, int times ) {
        for (int i =1; i<=times; i++) {
            lc.add(new Card(code,i));
        }
    }

    public static void shuffle(List<Card> lc) {
        Random rand = new Random();
        for (int i=0; i<lc.size(); i++) {
            int randid = rand.nextInt(lc.size());
            Card tmp = lc.get(i);
            lc.set(i, lc.get(randid));
            lc.set(randid, tmp);
        }
    }

    public static void sendCard(List<Card> lc, Set<Card> sc) {
        sc.add(lc.remove(0));
    }
}
